package Z_TopicPattern;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import utils.RabbitMQUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * @author： pang-yun
 * @date： 2021-12-20 14:04
 * 功能目的 ：用于
 */

public class TopicProducer {
    public static void main(String[] args) throws IOException, TimeoutException {
        // 获取信道
        Channel channel = RabbitMQUtils.getChannel();
        //交换机
        channel.exchangeDeclare(TopicConst.EXCHANGE_NAME, BuiltinExchangeType.TOPIC);

        // 发送消息
        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()){
            String message = scanner.next();
            while (scanner.hasNext()){
                String route = scanner.next();
                channel.basicPublish(TopicConst.EXCHANGE_NAME ,route,null,message.getBytes(StandardCharsets.UTF_8));
                System.out.println("message: "+ message + '\n' + "route : " +route);
            }
        }
    }
}
